<#include "./template/general_temp.ftl">

<#macro content>
<div class="row">
    <div class="box col-md-12">
        <div class="box-inner">
            <div class="box-header well" data-original-title="">
                <h2><i class="glyphicon glyphicon-posts"></i>基础信息管理</h2>

                <div class="box-icon">
                    <a href="#" class="btn btn-setting btn-round btn-default"><i class="glyphicon glyphicon-cog"></i></a>
                    <a href="#" class="btn btn-minimize btn-round btn-default"><i
                            class="glyphicon glyphicon-chevron-up"></i></a>
                    <a href="#" class="btn btn-close btn-round btn-default"><i class="glyphicon glyphicon-remove"></i></a>
                </div>
            </div>
            <div class="box-content" id="box-content">
                <div class="alert alert-info box col-md-12">
                    <div class="box col-md-6">
                        <a class="btn btn-success" href="${base}/system/baseInfo/add"><i class="glyphicon glyphicon-plus icon-white"></i>新增</a>
                    </div>
                    <div class="box" style="float:right">
                        <form class="form-inline" role="form">
                            <div class="form-group">
                                <label class="control-label" for="name">名称：</label>
                                <input type="text" name="name" class="form-control" id="name" placeholder="请输入要查询的名称">
                            </div>
                            <button type="button" onclick="queryData()" class="btn btn-default"><i class="glyphicon glyphicon-search"></i></button>
                        </form>
                    </div>
                </div>

                <table id="posts_dg">
                </table>
            </div>
        </div>
    </div>
    <!--/span-->

</div><!--/row-->
</#macro>
<#macro script>
<script type="text/javascript">
    function getQueryCondition(){
        var name = $("#name").val();
        return {"name":name};
    }
    function queryData(){
        var pars=getQueryCondition();
        var resetCss={
            checkbox:'position: absolute;left: 30px;top: 10px;',
            button:'margin-left: 80px;'
        };
        //构造列表
        jQuery('#posts_dg').datagrid({
            url:'${base}/system/baseInfo/list',
            fitColumns : true,
            striped : true,
            pagination : true,
            rownumbers : true,
            pageSize : 20,
            pageNumber : 1,
            pageList : [ 10,20, 50],
            loadMsg : '数据正在加载中...',
            singleSelect:true,
            queryParams : pars,
            selectOnCheck : false,
            checkOnSelect : false,
            width:$('.box-content').width() * 0.985,
            columns : [[
                {field : 'name', title : '案例名称',  resizable : true, hidden : false, sortable : false, width:$(this).width()*0.04, align: 'center'},
                {field : 'trappedPersonNum', title : '被困人数',  resizable : true, hidden : false, sortable : false, width:$(this).width()*0.02, align: 'center'},
                {field : 'explosion', title : '爆炸规模(%)',  resizable : true, hidden : false, sortable : false, width:$(this).width()*0.023, align: 'center'},
                {field : 'co', title : 'CO含量(万分之)',  resizable : true, hidden : false, sortable : false, width:$(this).width()*0.03, align: 'center'},
                {field : 'gas', title : '瓦斯含量(%)',  resizable : true, hidden : false, sortable : false, width:$(this).width()*0.023, align: 'center'},
                {field : 'ventilation', title : '通风系统破坏程度(%)',  resizable : true, hidden : false, sortable : false, width:$(this).width()*0.035, align: 'center'},
                {field : 'collapse', title : '坍塌情况(%)',  resizable : true, hidden : false, sortable : false, width:$(this).width()*0.023, align: 'center'},
                {field : 'secondaryExplosion', title : '二次爆炸影响情况(%)',  resizable : true, hidden : false, sortable : false, width:$(this).width()*0.03, align: 'center'},
                {field : 'fireHazard', title : '是否引发火灾',  resizable : true, hidden : false, sortable : false, width:$(this).width()*0.025, align: 'center'},
                {field : 'person', title : '专家名称',  resizable : true, hidden : false, sortable : false, width:$(this).width()*0.019, align: 'center'},
                {field : 'createTimeStr', title : '创建时间',  resizable : true, hidden : false, sortable : false, width:$(this).width()*0.025, align: 'center'},
                {field : 'ctrl', title : '操作',  resizable : true, hidden : false, sortable : false, width:$(this).width()*0.045, align: 'center',
                    formatter:function(value,row,index){
                        var editBtn = "<a class='btn btn-info' href='javascript:void(0)' style='' onclick='edit(" + row.id +")'><i class='glyphicon glyphicon-edit icon-white'></i>编辑</a> &nbsp;";

                        var delBtn = "<a class='btn btn-primary' href='javascript:void(0)'  onclick='del(" + row.id +")'><i class='glyphicon glyphicon-edit icon-white'></i>删除</a>";

                        return editBtn + delBtn;
                    }
                }
            ]],
            onLoadSuccess:function(data){
            },
            onClickRow: function (rowIndex, rowData) {

            }
        });
    }

    $(document).ready(function () {
        queryData();
    });

    function edit(id){
        window.location = "${base}/system/baseInfo/edit?id=" + id;
    }

    function del(id){
        if(window.confirm("确认删除？")) {
            jQuery.ajax({
                type: "POST",
                url: '${base}/system/baseInfo/delete',
                dataType:"json",
                data: {"id": id},
                success: function(data){
                    if(data.status == 1) {
                        alert("删除成功！");
                        queryData();
                    }
                },
                error: function (obj){
                    console.info(obj);
                }
            });
        }
    }
</script>
</#macro>
